package com.edais.actions;

import com.edais.domain.*;
import com.edais.domain.sina.City;
import com.edais.log.IpLog;
import com.edais.service.*;
import com.edais.util.*;
import com.edais.util.weixinAbout.SendWeiXinUtil;
import com.edais.vo.UserBankCardVo;
import com.yunzhi.domain.RequestHeader;
import com.yunzhi.domain.ResultCode;
import com.yunzhi.domain.ResultConstant;
import com.yunzhi.domain.ResultDTO;
import com.yunzhi.util.RequestUtil;
import com.yunzhi.util.ResponseUtil;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/thirdRoute")
public class ThirdProductRouteAction implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private static final Log logger = LogFactory.getLog(ThirdProductRouteAction.class);
	
	@Autowired
	private ThirdProductRouteService thirdProductRouteService;
	
	@Autowired
	private ErrorMessageService errorMessageService;
	
	@Autowired
	private UserCardService userCardService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private CenterService centerService;
	
	@Autowired
	private SMSService sMSService;
	
	@Autowired
	private WeixinBindingService weixinBindingService;
	
	@Autowired
	private CaptchaService captchaService;

	@Autowired
	private WithdrawsCashService withdrawsCashService;

	@Autowired
	private RateRisesCouponsService rateRisesCouponsService;

	@Autowired
	private OptionService optionsService;
	
	/**
	 * 卡bin查询
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/cardBinQuery")
	public void cardBinQuery(HttpServletRequest request, HttpServletResponse response) {
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");   // 用户id
		String cardNumber = paramsMap.get("cardNumber");
		// 用户id为空
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/cardBinQuery 传入参数为空-----userId");
			return;
		}
		//银行卡号为空
		if (StringUtils.isBlank(cardNumber)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00003,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/cardBinQuery 传入参数为空-----cardNumber");
			return;
		}
		
		try{
			String productCode = "card_bin";
			String bankName = "-1";
			String logInfo = "查询卡bin路由" + userId + "-";
			
			//根据银行名称获取查询卡bin路由
			List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(bankName, productCode);
			if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
				logger.error(logInfo + "根据银行名称获取查询卡bin路由失败" + bankName + "-" + productCode);
				String result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("BUSINESSE_ERROR"),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001, getErrorMessage(errorMessageService.getErrorMessage("BUSINESSE_ERROR")));
				CommonUtil.responseJson(result, response);
				return;
			}
			ThirdProductRoute thirdProductRoute = thirdProductRoutes.get(0);
			String thirdProductCode = thirdProductRoute.getThirdProductCode();
			String thirdProductBankCode = thirdProductRoute.getThirdPlatformCode();
			
			Map<String,Object> reqMap = new HashMap<String,Object>();
			reqMap.put("userId", userId);
			reqMap.put("cardNumber", cardNumber);
			reqMap.put("thirdProductBankCode", thirdProductBankCode);
			
			Map<String, Object> jsonMap = this.thirdProductRouteService.cardBinQuery(reqMap, thirdProductCode);
			
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
			
		}catch (Exception e) {
			logger.debug("/thirdRoute/cardBinQuery 查询卡bin提现 异常：" + e.getMessage());
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 单笔支付
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/singlePay")
	public void singlePay(HttpServletRequest request, HttpServletResponse response) {
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");   // 用户id
		String cardNumber = paramsMap.get("cardNumber");
		String payFlag = paramsMap.get("payFlag");
		String tradeAmount = paramsMap.get("tradeAmount");
		String mobile = paramsMap.get("mobile");
		
		// 用户id为空
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/singlePay 传入参数为空-----userId");
			return;
		}
		// 用户id为空
		if (StringUtils.isBlank(mobile)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/singlePay 传入参数为空-----mobile");
			return;
		}
		//银行卡号为空
		if (StringUtils.isBlank(cardNumber)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/singlePay 传入参数为空-----cardNumber");
			return;
		}
		//支付标识不能为空
		if (StringUtils.isBlank(payFlag)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/singlePay 传入参数为空-----payFlag");
			return;
		}
		//充值金额不能为空
		if (StringUtils.isBlank(tradeAmount)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/singlePay 传入参数为空-----tradeAmount");
			return;
		}
		//充值金额 不能小于0
		BigDecimal tradeAmountBig = new BigDecimal(tradeAmount);
		
		if(tradeAmountBig.compareTo(BigDecimal.ZERO)<=0){
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00003,
					Message.CnDescriptionExpression.EXTRACTMONEY_IS_ZERO);
				CommonUtil.responseJson(result, response);
				logger.debug("/thirdRoute/singlePay 传入参数为空-----tradeAmount");
				return;
		}
		
		
		try{
			String reqOrderId = createNoOrder("LB"+payFlag);
			String userIp = request.getRemoteAddr();
			paramsMap.put("reqOrderId", reqOrderId);
			paramsMap.put("userIp", userIp);
			Map<String,Object> paramMap = new HashMap<String,Object>();
			paramMap.put("userId", userId);
			List<UserRecePayCard> userCardList = this.userCardService.queryUserCardListInfoByUserId(paramMap);
			Bank bank = null;
			String rescode = "";
			String bankCode = "";
			String result = "";
			if(userCardList==null || userCardList.size() ==0){
				String productCode = "card_bin";
				String bankName = "-1";
				String logInfo = "查询卡bin路由" + userId + "-";

				//根据银行名称获取查询卡bin路由
				List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(bankName, productCode);
				if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
					logger.error(logInfo + "根据银行名称获取查询卡bin路由失败" + bankName + "-" + productCode);
					result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("THIRD_ROUTE_ERROR"),
							Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001, getErrorMessage(errorMessageService.getErrorMessage("THIRD_ROUTE_ERROR")));
					CommonUtil.responseJson(result, response);
					return;
				}
				ThirdProductRoute thirdProductRoute = thirdProductRoutes.get(0);
				String thirdProductCode = thirdProductRoute.getThirdProductCode();
				String thirdProductBankCode = thirdProductRoute.getThirdPlatformCode();
				Map<String,Object> reqMap = new HashMap<String,Object>();
				reqMap.put("userId", userId);
				reqMap.put("cardNumber", cardNumber);
				reqMap.put("thirdProductBankCode", thirdProductBankCode);

				Map<String, Object> cardBinResMap = this.thirdProductRouteService.cardBinQuery(reqMap, thirdProductCode);

				rescode = cardBinResMap.get("rescode").toString();

				if(!rescode.equals(Consts.SUCCESS_CODE)){
					result = JsonUtil.getJsonStringFromMap(cardBinResMap);
					// 处理返回结果
					CommonUtil.responseJson(result, response);
					return;
				}
				 bankCode = cardBinResMap.get("bankCode").toString();
				 paramMap.put("bankCode", bankCode);
				 bank = this.userCardService.queryBankInfoByBankCode(paramMap);
				 
				 paramsMap.put("bankCode", bankCode);
				//保存银行卡信息
				Map<String,Object> saveCardResMap = this.thirdProductRouteService.saveCardInfo(paramsMap);
				rescode = saveCardResMap.get("rescode").toString();
				
				if(!rescode.equals(Consts.SUCCESS_CODE)){
					result = JsonUtil.getJsonStringFromMap(saveCardResMap);
					// 处理返回结果
					CommonUtil.responseJson(result, response);
					return;
				}
			}else{
				UserRecePayCard urp = userCardList.get(0);
				int bankId = urp.getBank_id();
				paramMap.put("bankId", bankId);
				
				bank =  this.userCardService.queryBankInfoByBankCode(paramMap);
				
				bankCode = bank.getYlbankcode();
				
				 paramsMap.put("bankCode", bankCode);
			}
			
			//查询支付的thirdProudctCode
			String productCode = "quick_singlepay";
			String bankName = bank.getBank_name();
			
			Map<String, String> queryRouteMap = new HashMap<String, String>();
			queryRouteMap.put("bankName", bankName);
			queryRouteMap.put("productCode", productCode);
			
			List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(queryRouteMap);
			
			if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
				result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("BUSINESSE_ERROR"),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001, Message.CnDescriptionExpression.BUSINESSE_ERROR);
				CommonUtil.responseJson(result, response);
				return;
			}
			
			//判断金额是否小于最低限额
			
			
			paramsMap.put("bankCode", bankCode);
			paramsMap.put("bankName", bankName);
			
			
			ThirdProductRoute singlePayProductRoute = thirdProductRoutes.get(0);
			String minLimit = singlePayProductRoute.getBankMinLimit()==null?"0.01":singlePayProductRoute.getBankMinLimit();
			BigDecimal bankMinLimitBig = new BigDecimal(minLimit);
			
			if(tradeAmountBig.compareTo(bankMinLimitBig)<0){
				String [] attr = new String[]{singlePayProductRoute.getBankMinLimit()};
				result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("BANK_MIN_LIMIT_ERROR",attr),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,  getErrorMessage(errorMessageService.getErrorMessage("BANK_MIN_LIMIT_ERROR",attr)));
				CommonUtil.responseJson(result, response);
				return;
			}
			
			//判断金额是否大于最大限额
			String maxLimit = singlePayProductRoute.getBankLimit()==null?"-1":singlePayProductRoute.getBankLimit();
			BigDecimal bankMaxLimitBig = new BigDecimal(maxLimit);
			
			if(tradeAmountBig.compareTo(bankMaxLimitBig)>0){
				String [] attr = new String[]{singlePayProductRoute.getBankLimit()};
				result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("BANK_MAX_LIMIT_ERROR",attr),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,  getErrorMessage(errorMessageService.getErrorMessage("BANK_MAX_LIMIT_ERROR",attr)));
				CommonUtil.responseJson(result, response);
				return;
			}
			
			paramsMap.put("singlePayProductRoute", singlePayProductRoute.getThirdProductCode());
			paramsMap.put("thirdPlatformCode", singlePayProductRoute.getThirdPlatformCode());
			Map<String,Object> resultMap = this.thirdProductRouteService.saveOrderInfo(paramsMap);
		    result = JsonUtil.getJsonStringFromMap(resultMap);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
			
		}catch (Exception e) {
			logger.debug("/thirdRoute/singlePay 单笔支付 异常：" + e.getMessage());
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			return;
		}
		
	}
	
	/**
	 * 单笔支付回调
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/singlePayNotify")
	public void singlePayNotify(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String reqOrderId = paramsMap.get("reqOrderId");
		String payFlag = paramsMap.get("payFlag");
		String tradeAmount = paramsMap.get("tradeAmount");
		String resOrderId = paramsMap.get("resOrderId");
		String receiveMessage = paramsMap.get("receiveMessage");
		String logInfo = "rechargeNotify" + resOrderId + "-";
		logger.info(logInfo + "调用javaservice参数：" + paramsMap.toString()) ;
		//支付标识不能为空
		if (StringUtils.isBlank(payFlag)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00003,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.info("/thirdRoute/singlePayNotify 传入参数为空-----payFlag");
			return;
		}
		//充值金额不能为空
		if (StringUtils.isBlank(tradeAmount)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00003,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.info("/thirdRoute/singlePayNotify 传入参数为空-----tradeAmount");
			return;
		}
		//上送订单号不能为空
		if (StringUtils.isBlank(reqOrderId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00003,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.info("/thirdRoute/singlePayNotify 传入参数为空-----reqOrderId");
			return;
		}
		//返回订单号不能为空
		if (StringUtils.isBlank(resOrderId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00003,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.info("/thirdRoute/singlePayNotify 传入参数为空-----resOrderId");
			return;
		}
		//返回报文不能为空
		if (StringUtils.isBlank(receiveMessage)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00003,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.info("/thirdRoute/singlePayNotify 传入参数为空-----receiveMessage");
			return;
		}
		
		try{
			Map<String,Object> requestMap = new HashMap<String,Object>();
			requestMap.put("reqOrderId", reqOrderId);
			requestMap.put("payFlag", payFlag);
			requestMap.put("tradeAmount", tradeAmount);
			requestMap.put("resOrderId", resOrderId);
			requestMap.put("receiveMessage", receiveMessage);
			
			jsonMap = this.thirdProductRouteService.singlePayNotify(requestMap);
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			
			if(Consts.SUCCESS_CODE.equals(jsonMap.get("rescode"))){
				String userId = String.valueOf(jsonMap.get("userId")==null?"":jsonMap.get("userId"));
				//发送短信或微信
				sendMeidaAndSMS(userId,paramsMap, tradeAmount);
				//发送个推消息----add by gongyanlan
				String smsNo="sms01001";//充值,config_sms表中参数,
				String mobile = captchaService.getMobileById(userId);//通过用户ID查询使用手机号
				String[] smsParams={tradeAmount,"",""};
				Map<String,Object> map=new HashMap<String,Object>();
				map.put("userId", userId);
				map.put("mobile", mobile);
				map.put("title", "充值成功通知");//标题
				map.put("messageDetailTypeNew", "3");//1.订制商品个人消息，2.还款成功，3.充值，4.投资，5,提现
				map.put("messageDetailResult", "0");//0.执行成功消息提示，1.执行失败提示
				map.put("smsParams", smsParams);//消息模板里需要替换的变量
				map.put("smsNo", smsNo);
				sMSService.sendGetuiMSG(map);
			}else if("99998".equals(jsonMap.get("rescode"))){
				jsonMap.put("rescode", Consts.SUCCESS_CODE);
			}
			logger.info(logInfo + "调用核心返回结果：" + result) ;
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}catch (Exception e) {
			logger.debug("/thirdRoute/singlePay 单笔支付回调 异常：" + e.getMessage());
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 获取进入充值页面需要的参数
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/getGoPayAllInfo")
	public void getGoPayAllInfo(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");
		String mobile = paramsMap.get("mobile");
		
		// 用户id为空
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/singlePay 传入参数为空-----userId");
			return;
		}
		// 用户id为空
		if (StringUtils.isBlank(mobile)) {
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/singlePay 传入参数为空-----mobile");
			return;
		}
		
		/**
		 * 需要返回的数值
		 * 1.查询主账户信息 acctBalance userId mobile
		 * 2.查询实名认证信息  isAuth
		 * 3.查询用户银行卡信息  isBind bankCardNo bankCardName bankCardPicPath
		 * 4.查询单笔限额信息 singleDayLimit singleMothLimit payFlag singleLimit
		 */
		
		//判断用户是否存在
		Map<String,Object> userParamMap = new HashMap<String,Object>();
		userParamMap.put("userId", userId);
		userParamMap.put("mobile", mobile);
		try {
			User user = userService.getUserByParm(userParamMap);
			
			if(user==null){
				String result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("USER_NOT_EXIST"), 
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
					getErrorMessage(errorMessageService.getErrorMessage("USER_NOT_EXIST")));
				CommonUtil.responseJson(result, response);
				return;
			}
			
			if (!"Y".equals(user.getIdcard_validate()) ||  !"1".equals(user.getIs_create_acct())) {
				
				String result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("AUTHENTICATION_IS_NOT"), 
						Consts.NOT_AUTH_CODE, Consts.ErrorMsg.MSG00001,
						getErrorMessage(this.errorMessageService.getErrorMessage("AUTHENTICATION_IS_NOT")));
					CommonUtil.responseJson(result, response);
				return ;
			}
			
			/*
			 * 查询主账户信息 acctBalance userId mobile
			 */
			
			Map<String, Object> pageMode = new HashMap<String, Object>();
			pageMode.put("userId", userId);

			Map resMap = centerService.getCusBalance(pageMode);
			if (resMap != null && "00000".equals(resMap.get("rescode"))) {
				String acctBalance = resMap.get("ACCTBALANCE") + "";
				jsonMap.put("acctBalance", acctBalance == null || "".equals(acctBalance) ? "0.00" : acctBalance);// 余额
			} else {
				logger.error("查询余额E300012失败:" + resMap.get("resmsg"));
				String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.QUERY_FAILED);
				CommonUtil.responseJson(result, response);
				return;
			}
			/*
			 * 查询实名认证信息  isAuth
			 */
			String idcardValidate = "N";
			if ("Y".equals(user.getIdcard_validate()) && "1".equals(user.getIs_create_acct())) {
				UserInfo userInfo = userService.getUserInfo(userId);
				if(userInfo!=null){
					idcardValidate = "Y";
				}
			}
			
			jsonMap.put("idcardValidate", idcardValidate);
			String rescode = Consts.SUCCESS_CODE;
			String resmsg_cn = "查询成功";
			/*
			 * 查询用户银行卡信息  isBind bankCardNo bankCardName bankCardPicPath
			 */
			Map<String,Object> paramMap = new HashMap<String,Object>();
			paramMap.put("userId", userId);
			List<UserRecePayCard> userCardList = this.userCardService.queryUserCardListInfoByUserId(paramMap);
			String isBindCard = "N";
			if(userCardList != null && userCardList.size() > 0){
				UserRecePayCard userRecePayCard = userCardList.get(0);
				isBindCard = "Y";
				String bankCardNumber = userRecePayCard.getCard_number();
				paramMap.put("bankId", userRecePayCard.getBank_id());
				Bank bank = this.userCardService.queryBankInfoByBankCode(paramMap);
				String bankName = bank.getBank_name();
				String  bankPicPath = bank.getPicture();
				
				/*
				 * 查询单笔限额信息 singleDayLimit singleMothLimit payFlag singleLimit
				 */
				//查询支付的thirdProudctCode
				String productCode = "quick_singlepay";
				
				Map<String, String> queryRouteMap = new HashMap<String, String>();
				queryRouteMap.put("bankName", bankName);
				queryRouteMap.put("productCode", productCode);
				
				jsonMap.put("bankCardNumber", bankCardNumber);
				jsonMap.put("bankName", bankName);
				jsonMap.put("bankPicPath", bankPicPath);
				
				
				List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(queryRouteMap);
				if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
					rescode = "00004";
					resmsg_cn = getErrorMessage(this.errorMessageService.getErrorMessage("THIRD_ROUTE_ERROR"));
				}else{
					ThirdProductRoute thirdProductRoute = thirdProductRoutes.get(0);
					
					jsonMap.put("bankDayLimit",thirdProductRoute.getBankDayLimit());
					jsonMap.put("bankMonthLimit",thirdProductRoute.getBankMonthLimit());
					jsonMap.put("bankMinLimit",thirdProductRoute.getBankMinLimit());
					jsonMap.put("bankLimit",thirdProductRoute.getBankLimit());
					
				}
				
				
			}
			jsonMap.put("rescode", rescode);
			jsonMap.put("resmsg_cn", resmsg_cn);
			jsonMap.put("isBindCard", isBindCard);
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		} catch (Exception e) {
			logger.debug("/thirdRoute/getGoPayAllInfo setResultStringCn 异常：" + e.getMessage());
			String result = CommonUtil.setResultStringCn(new HashMap<String, Object>(), 
				Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
				Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			return;
		}
	}
	
	/**
	 * 随机生成订单a
	 * @param title
	 * @return
	 */
	public String createNoOrder(String title) {
		Date now = new Date();
		SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String currTime = outFormat.format(now);

		String strReq = currTime;
		Random random = new Random();
		String result = "";
		for (int i = 0; i < 8; i++) {
			result += random.nextInt(10);
		}

		String requestNo = title.toUpperCase() + strReq + result;
		return requestNo;
	}
	
	/**
	 * 获取返回的信息
	 * @param errorMessageMap
	 * @return
	 */
	public String getErrorMessage(Map<String,Object> errorMessageMap){
		ErrorMessageSetting ems = (ErrorMessageSetting) errorMessageMap.get("errorMessage");
		String messageContent =  ems.getMessage_content();
		return messageContent;
	}

	/**
	 * 查询用户银行卡信息
	 * @param request			请求
	 * @param response		响应
	 */
	@RequestMapping(value = "/queryCardAllInfo")
	public void queryCardAllInfo(HttpServletRequest request, HttpServletResponse response){
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		String result;
		String rescode;
		String bankCode;

		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");
		String mobile = paramsMap.get("mobile");
		String cardNumber = paramsMap.get("cardNumber");
		Map<String,Object> paramMap = new HashMap<String,Object>();
		// 用户id为空
		if (StringUtils.isBlank(userId)) {
			result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/queryCardAllInfo 传入参数为空-----userId");
			return;
		}
		// 用户id为空
		if (StringUtils.isBlank(mobile)) {
			result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			logger.debug("/thirdRoute/queryCardAllInfo 传入参数为空-----mobile");
			return;
		}

		//判断用户是否存在
		Map<String,Object> userParamMap = new HashMap<String,Object>();
		userParamMap.put("userId", userId);
		userParamMap.put("mobile", mobile);
		try {
			User user = userService.getUserByParm(userParamMap);

			if(user==null){
				result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("USER_NOT_EXIST"),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
						getErrorMessage(errorMessageService.getErrorMessage("USER_NOT_EXIST")));
				CommonUtil.responseJson(result, response);
				return;
			}

			String productCode = "card_bin";
			String bankName = "-1";
			String logInfo = "查询用户银行卡信息" + userId + "-";

			//根据银行名称获取查询卡bin路由
			List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(bankName, productCode);
			if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
				logger.error(logInfo + "根据银行名称获取查询卡bin路由失败" + bankName + "-" + productCode);
				result = CommonUtil.setResultStringCn(errorMessageService.getErrorMessage("BUSINESSE_ERROR"),
						Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001, Message.CnDescriptionExpression.BUSINESSE_ERROR);
				CommonUtil.responseJson(result, response);
				return;
			}
			ThirdProductRoute thirdProductRoute = thirdProductRoutes.get(0);
			String thirdProductCode = thirdProductRoute.getThirdProductCode();
			String thirdProductBankCode = thirdProductRoute.getThirdPlatformCode();
			Map<String,Object> reqMap = new HashMap<String,Object>();
			reqMap.put("userId", userId);
			reqMap.put("cardNumber", cardNumber);
			reqMap.put("thirdProductBankCode", thirdProductBankCode);

			Map<String, Object> cardBinResMap = this.thirdProductRouteService.cardBinQuery(reqMap, thirdProductCode);

			rescode = cardBinResMap.get("rescode").toString();

			if(!rescode.equals(Consts.SUCCESS_CODE)){
				result = JsonUtil.getJsonStringFromMap(cardBinResMap);
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				return;
			}
			bankCode = cardBinResMap.get("bankCode").toString();

			paramMap.put("bankCode", bankCode);
			Bank bank = this.userCardService.queryBankInfoByBankCode(paramMap);

			//查询支付的thirdProudctCode
			productCode = "quick_singlepay";
			bankName = bank.getBank_name();

			Map<String, String> queryRouteMap = new HashMap<String, String>();
			queryRouteMap.put("bankName", bankName);
			queryRouteMap.put("productCode", productCode);

			thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(queryRouteMap);

			String thirdRouteRescode = Consts.SUCCESS_CODE;
			String thirdRouteResMsg = "查询成功";
			if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
				thirdRouteRescode = "00004";
				thirdRouteResMsg =  getErrorMessage(this.errorMessageService.getErrorMessage("THIRD_ROUTE_ERROR"));
			}else{
				thirdProductRoute = thirdProductRoutes.get(0);
				jsonMap.put("bankDayLimit",thirdProductRoute.getBankDayLimit());
				jsonMap.put("bankMonthLimit",thirdProductRoute.getBankMonthLimit());
				jsonMap.put("bankMinLimit",thirdProductRoute.getBankMinLimit());
				jsonMap.put("bankLimit",thirdProductRoute.getBankLimit());
			}
			jsonMap.put("bankCardNumber", cardNumber);
			jsonMap.put("bankName", bank.getBank_name());
			jsonMap.put("bankPicPath", bank.getPicture());
			jsonMap.put("rescode", thirdRouteRescode);
			jsonMap.put("resmsg_cn", thirdRouteResMsg);
			result = JsonUtil.getJsonStringFromMap(jsonMap);
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			return;
		}catch (Exception e){
			logger.debug("/thirdRoute/queryCardAllInfo setResultStringCn 异常：" + e.getMessage());
			result = CommonUtil.setResultStringCn(new HashMap<String, Object>(),
					Consts.ERROR_CODE, Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
			return;
		}

	}
	
	/**
	 * 根据USERID发送短信/微信
	 * @param userId
	 */
	public void sendMeidaAndSMS(String userId,Map<String,String> paramsMap,String moneyOrder) throws Exception{
		//封装用户ID
		WeixinMediaBinding mediaBinding = new WeixinMediaBinding();
		mediaBinding.setUserId(Integer.parseInt(userId));
		
		//先推送微信，微信成功不发短信，失败再发短信
		String mobile = captchaService.getMobileById(userId);//通过用户ID查询使用手机号
		String mediaUid = weixinBindingService.queryMediaUid(mediaBinding);//通过用户ID实体类查询微信标识
		
		//TODO 逻辑判断
		if(null == mediaUid || "null".equalsIgnoreCase(mediaUid) || "".equalsIgnoreCase(mediaUid)){
			logger.info("[推送短信息]因手机号："+mobile+"并未绑定微信");
			//发送短信
			String cpType="";
			String smsNo="sms01001";//config_sms表中参数
			String tsje=moneyOrder;
			if (StringUtils.isBlank(userId) 
					|| StringUtils.isBlank(smsNo)|| StringUtils.isBlank(tsje)) {
				logger.debug("deposit/join sendSMS 传入参数为空");
			}
			try{
				// 发送短信
				if(StringUtils.isEmpty(cpType)){
					 sMSService.getSMS(userId,smsNo,tsje);	
				}else{
					sMSService.getSMS(userId,smsNo,tsje,cpType);	
				}
			} catch (Exception e) {
				logger.error("deposit/join sendSMS异常:" + e.getCause());
			}
		}else{
			Map<String,String> weixinTMap = new HashMap<String,String>();
			weixinTMap.put("mediaUid", mediaUid);//微信用户唯一标识 
			weixinTMap.put("money", moneyOrder);//充值金额
			weixinTMap.put("functionScope", "recharge");//推送类型
			
			boolean sendRusult = SendWeiXinUtil.sendWeiXin(weixinTMap);
			if(!sendRusult){
				logger.info("[微信推送失败][推送短信息]因手机号："+mobile+"并未绑定微信或者未关注联币钱包微信号");
				//发送短信
				String cpType="";
				String smsNo="sms01001";//config_sms表中参数
				String tsje=moneyOrder;
				if (StringUtils.isBlank(userId) 
						|| StringUtils.isBlank(smsNo)|| StringUtils.isBlank(tsje)) {
					logger.debug("deposit/join sendSMS 传入参数为空");
				}
				try{
					// 发送短信
					if(StringUtils.isEmpty(cpType)){
						 sMSService.getSMS(userId,smsNo,tsje);	
					}else{
						sMSService.getSMS(userId,smsNo,tsje,cpType);	
					}
				} catch (Exception e) {
					logger.error("deposit/join sendSMS异常:" + e.getCause());
				}
			}else{
				logger.info("[微信推送]手机号："+mobile+"推送成功");
			}
		}
	}
	
	/**
	 * Api单笔支付
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/apiSinglePay")
	public void apiSinglePay(HttpServletRequest request, HttpServletResponse response) {
		try{
			String logInfo="";
			if (!RequestUtil.validSign(request)) {
				logger.info("无效签名");
				ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
				return;
			}
			if (!RequestUtil.validToken(request)) {
				logger.info("无效token");
				ResponseUtil.write(response, ResultConstant.INVALID_TOKEN);
				return;
			}
			RequestHeader header = RequestUtil.decodeHeader(request);
			logger.info("header：" + header.toString());
			
			Long userIdLong = header.getUserId();
			if (userIdLong == null) {
				ResponseUtil.write(response, ResultConstant.NOT_LOGIN);
				return;
			}
		    User user = this.userService.getUserDetail(userIdLong.toString());
		    if(user==null){
		    	ResultDTO<String> result = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, result);
				return;
		    }
		    
			// 解密请求参数
			logInfo="用户ID="+userIdLong;
			com.alibaba.fastjson.JSONObject jsonMap = RequestUtil.decodeDataJson(request);
			logger.info("data：" + jsonMap.toString());
			
			String userId = userIdLong.toString();   // 用户id
			String cardNumber = jsonMap.getString("cardNumber");
			String payFlag = jsonMap.getString("payFlag");
			String tradeAmount = jsonMap.getString("tradeAmount");
			String mobile=  jsonMap.getString("mobile");
					 
			Map<String,String> paramsMap = new HashMap<String,String>();
			paramsMap.put("userId", userId);
			paramsMap.put("cardNumber", cardNumber);
			paramsMap.put("payFlag", payFlag);
			paramsMap.put("tradeAmount", tradeAmount);
			paramsMap.put("mobile", mobile);
			
			if (StringUtils.isBlank(mobile)) {
				logger.info(logInfo+"API单笔支付：手机号为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			// 用户id为空
			if (StringUtils.isBlank(userId)) {
				logger.info(logInfo+"API单笔支付：用户ID为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			//银行卡号为空
			if (StringUtils.isBlank(cardNumber)) {
				logger.info(logInfo+"API单笔支付：cardNumber为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			//支付标识不能为空
			if (StringUtils.isBlank(payFlag)) {
				logger.info(logInfo+"API单笔支付：payFlag为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			//充值金额不能为空
			if (StringUtils.isBlank(tradeAmount)) {
				logger.info(logInfo+"API单笔支付：tradeAmount为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			//充值金额 不能小于0
			BigDecimal tradeAmountBig = new BigDecimal(tradeAmount);
			
			if(tradeAmountBig.compareTo(BigDecimal.ZERO)<=0){
					
				logger.info(logInfo+"API单笔支付：充值金额小于0为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.EXTRACTMONEY_IS_ZERO);
				ResponseUtil.write(response, checkDto);
				return;
			}
		
		
		
			String reqOrderId = createNoOrderLength20("LB"+payFlag);
			String userIp = request.getRemoteAddr();
			paramsMap.put("reqOrderId", reqOrderId);
			paramsMap.put("userIp", userIp);
			Map<String,Object> paramMap = new HashMap<String,Object>();
			paramMap.put("userId", userId);
			List<UserRecePayCard> userCardList = this.userCardService.queryUserCardListInfoByUserId(paramMap);
			Bank bank = null;
			String rescode = "";
			String bankCode = "";
			String result = "";
			String resmsg = "";
			if(userCardList==null || userCardList.size() ==0){
				String productCode = "card_bin";
				String bankName = "-1";
				logInfo += "查询卡bin路由" + userId + "-";

				//根据银行名称获取查询卡bin路由
				List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(bankName, productCode);
				if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
					logger.error(logInfo + "根据银行名称获取查询卡bin路由失败" + bankName + "-" + productCode);
					ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
							getErrorMessage(errorMessageService.getErrorMessage("THIRD_ROUTE_ERROR")));
					ResponseUtil.write(response, checkDto);
					return;
				}
				ThirdProductRoute thirdProductRoute = thirdProductRoutes.get(0);
				String thirdProductCode = thirdProductRoute.getThirdProductCode();
				String thirdProductBankCode = thirdProductRoute.getThirdPlatformCode();
				Map<String,Object> reqMap = new HashMap<String,Object>();
				reqMap.put("userId", userId);
				reqMap.put("cardNumber", cardNumber);
				reqMap.put("thirdProductBankCode", thirdProductBankCode);

				Map<String, Object> cardBinResMap = this.thirdProductRouteService.cardBinQuery(reqMap, thirdProductCode);

				rescode = cardBinResMap.get("rescode").toString();

				if(!rescode.equals(Consts.SUCCESS_CODE)){
					logger.error(logInfo + "卡Bin查询出错");
					resmsg = cardBinResMap.get("resmsg_cn").toString();
					ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
							resmsg);
					ResponseUtil.write(response, checkDto);
					return;
				}
				 bankCode = cardBinResMap.get("bankCode").toString();
				 paramMap.put("bankCode", bankCode);
				 bank = this.userCardService.queryBankInfoByBankCode(paramMap);
				 
				 paramsMap.put("bankCode", bankCode);
				//保存银行卡信息
				Map<String,Object> saveCardResMap = this.thirdProductRouteService.saveCardInfo(paramsMap);
				rescode = saveCardResMap.get("rescode").toString();
				resmsg = saveCardResMap.get("resmsg_cn").toString();
				if(!rescode.equals(Consts.SUCCESS_CODE)){
					logger.error(logInfo + "保存银行卡出错");
					ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
							resmsg);
					ResponseUtil.write(response, checkDto);
					return;
				}
			}else{
				UserRecePayCard urp = userCardList.get(0);
				int bankId = urp.getBank_id();
				paramMap.put("bankId", bankId);
				
				bank =  this.userCardService.queryBankInfoByBankCode(paramMap);
				
				bankCode = bank.getYlbankcode();
				
				 paramsMap.put("bankCode", bankCode);
			}
			
			//查询支付的thirdProudctCode
			String productCode = "quick_api_singlepay";
			String bankName = bank.getBank_name();
			
			Map<String, String> queryRouteMap = new HashMap<String, String>();
			queryRouteMap.put("bankName", bankName);
			queryRouteMap.put("productCode", productCode);
			
			List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(queryRouteMap);
			
			if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
				logger.error(logInfo + "根据银行名称获取充值路由失败" + bankName + "-" + productCode);
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						getErrorMessage(errorMessageService.getErrorMessage("THIRD_ROUTE_ERROR")));
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			//判断金额是否小于最低限额
			
			
			paramsMap.put("bankCode", bankCode);
			paramsMap.put("bankName", bankName);
			
			
			ThirdProductRoute singlePayProductRoute = thirdProductRoutes.get(0);
			String minLimit = singlePayProductRoute.getBankMinLimit()==null?"0.01":singlePayProductRoute.getBankMinLimit();
			BigDecimal bankMinLimitBig = new BigDecimal(minLimit);
			
			if(tradeAmountBig.compareTo(bankMinLimitBig)<0){
				String [] attr = new String[]{singlePayProductRoute.getBankMinLimit()};
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						 getErrorMessage(errorMessageService.getErrorMessage("BANK_MIN_LIMIT_ERROR",attr)));
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			//判断金额是否大于最大限额
			String maxLimit = singlePayProductRoute.getBankLimit()==null?"-1":singlePayProductRoute.getBankLimit();
			BigDecimal bankMaxLimitBig = new BigDecimal(maxLimit);
			
			if(tradeAmountBig.compareTo(bankMaxLimitBig)>0){
				String [] attr = new String[]{singlePayProductRoute.getBankLimit()};
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						getErrorMessage(errorMessageService.getErrorMessage("BANK_MAX_LIMIT_ERROR",attr)));
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			paramsMap.put("singlePayProductRoute", singlePayProductRoute.getThirdProductCode());
			paramsMap.put("thirdPlatformCode", singlePayProductRoute.getThirdPlatformCode());
			ResultDTO<Map<String,Object>> resultDTO = this.thirdProductRouteService.saveApiOrderInfo(paramsMap);
			ResponseUtil.write(response, resultDTO);
			return;
			
		}catch (Exception e) {
			ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			ResponseUtil.write(response, checkDto);
			return;
		}
		
	}
	
	@RequestMapping(value = "/apiCheckCode")
	public void apiCheckCode(HttpServletRequest request, HttpServletResponse response) {
		
		try{
			
			String logInfo="";
			if (!RequestUtil.validSign(request)) {
				logger.info("无效签名");
				ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
				return;
			}
			if (!RequestUtil.validToken(request)) {
				logger.info("无效token");
				ResponseUtil.write(response, ResultConstant.INVALID_TOKEN);
				return;
			}
			RequestHeader header = RequestUtil.decodeHeader(request);
			logger.info("header：" + header.toString());
			
			Long userIdLong = header.getUserId();
			if (userIdLong == null) {
				ResponseUtil.write(response, ResultConstant.NOT_LOGIN);
				return;
			}
		    User user = this.userService.getUserDetail(userIdLong.toString());
		    if(user==null){
		    	ResultDTO<String> result = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, result);
				return;
		    }
		    
		    String mobile=user.getMobile();
			// 解密请求参数
			logInfo="用户ID="+userIdLong;
			com.alibaba.fastjson.JSONObject jsonMap = RequestUtil.decodeDataJson(request);
			logger.info("data：" + jsonMap.toString());
			
			Map<String, String> paramsMap = new HashMap<String,String>();
			
			String userId = userIdLong.toString();   // 用户id
			String requestOrderId = jsonMap.getString("requestOrderId");//订单号
			String checkCode = jsonMap.getString("checkCode");
			String payToken = jsonMap.getString("payToken");
			String bankName = jsonMap.getString("bankName");
			String resOrderId = jsonMap.getString("resOrderId");
			String phoneNumber = jsonMap.getString("phoneNumber");
			String bankAccountNo = jsonMap.getString("bankAccountNo");
			
			paramsMap.put("userId", userId);
			paramsMap.put("requestOrderId", requestOrderId);
			paramsMap.put("checkCode", checkCode);
			paramsMap.put("payToken", payToken);
			paramsMap.put("bankName", bankName);
			paramsMap.put("resOrderId", resOrderId);
			paramsMap.put("phoneNumber", phoneNumber);
			paramsMap.put("bankAccountNo", bankAccountNo);
			
			
			// 用户id为空
			if (StringUtils.isBlank(userId)) {
				logger.info(logInfo+"API单笔支付：用户Id为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(requestOrderId)) {
				logger.info(logInfo+"API单笔支付：requestOrderId为空");
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(checkCode)) {
				logger.info(logInfo+"API单笔支付：checkCode为空");
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(payToken)) {
				logger.info(logInfo+"API单笔支付：payToken为空");
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(bankName)) {
				logger.info(logInfo+"API单笔支付：bankName为空");
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(resOrderId)) {
				logger.info(logInfo+"API单笔支付：resOrderId为空");
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(bankAccountNo)) {
				logger.info(logInfo+"API单笔支付：bankAccountNo为空");
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(phoneNumber)) {
				logger.info(logInfo+"API单笔支付：phoneNumber为空");
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
		
		
			String userIp = request.getRemoteAddr();
			String result = "";
			
			//查询支付的thirdProudctCode
			String productCode = "quick_api_singlepay";
			
			Map<String, String> queryRouteMap = new HashMap<String, String>();
			queryRouteMap.put("bankName", bankName);
			queryRouteMap.put("productCode", productCode);
			
			List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(queryRouteMap);
			
			if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
				logger.error(logInfo + "根据银行名称获取API单笔充值路由失败" + bankName + "-" + productCode);
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						getErrorMessage(errorMessageService.getErrorMessage("THIRD_ROUTE_ERROR")));
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			ThirdProductRoute singlePayProductRoute = thirdProductRoutes.get(0);
			paramsMap.put("checkCodeThirdProductCode", singlePayProductRoute.getThirdProductCode());
			paramsMap.put("userIp", userIp);
			
			ResultDTO<Map<String,Object>> resultDTO = this.thirdProductRouteService.apiCheckCode(paramsMap);
		    ResponseUtil.write(response, resultDTO);
			return;
			
		}catch (Exception e) {
			ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			ResponseUtil.write(response, checkDto);
			return;
		}
	}
	
	public String createNoOrderLength20(String title) {
		Date now = new Date();
		SimpleDateFormat outFormat = new SimpleDateFormat("MMddHHmmss");
		String currTime = outFormat.format(now);

		String strReq = currTime;
		Random random = new Random();
		String result = "";
		for (int i = 0; i < 6; i++) {
			result += random.nextInt(10);
		}

		String requestNo = title.toUpperCase() + strReq + result;
		return requestNo;
	}

	/**
	 * 提现确认
	 *
	 * @param request
	 * @return response
	 * @throws IllegalAccessException
	 * @throws IllegalArgumentException
	 * @throws Exception
	 */
	@SuppressWarnings("unused")
	@RequestMapping(value = "/dealWithdrawal")
	public void dealWithdrawal(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		if (!RequestUtil.validSign(request)) {
			logger.info("无效签名");
			ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
			return;
		}
		if (!RequestUtil.validToken(request)) {
			logger.info("无效token");
			ResponseUtil.write(response, ResultConstant.INVALID_TOKEN);
			return;
		}

		// 解密请求参数
		RequestHeader header = RequestUtil.decodeHeader(request);
		logger.info("header：" + header.toString());
		com.alibaba.fastjson.JSONObject params = RequestUtil.decodeDataJson(request);
		logger.info("data：" + params);

		String userId = header.userId2String(); // 用户id
		String extractMoney = params.getString("extractMoney"); // 提现金额
		String recePayCardId = params.getString("recePayCardId"); // 回款卡号id
		String setupFlag = params.getString("setupFlag"); // 1网站的 2手机
		String passwordCash = params.getString("passwordCash"); // 交易密码
		String province = params.getString("province"); // 省份
		String city = params.getString("city"); // 城市
		String withdrawFlag = params.getString("withdrawFlag");
		withdrawFlag = StringUtils.isNotBlank(withdrawFlag) ? withdrawFlag : "LIANLIANPAY";
		String ip = CommonUtil.getClientIP(request);
		IpLogBean logBean = new IpLogBean();
		logBean.setIp(ip);
		logBean.setAction("提现申请");
		logBean.setUser(userId);
		logBean.setStatus(Consts.ERROR_CN);
		if ("2".equals(setupFlag)) {
			logBean.setDetail(userId + "在APP端进行了提现申请操作");
		} else {
			logBean.setDetail(userId + "在WEB端进行了提现申请操作");
		}
		String logInfo = "extractApply" + userId + "-";
		logger.info(logInfo + "入参：" + params.toString());

		BigDecimal extractMoneyBD;
		BigDecimal extractFeePayBD;
		BigDecimal acctBalanceBD;

		if (StringUtils.isBlank(userId)) {
			if (StringUtils.isNotBlank(ip)) {
				IpLog.printIpLog(logBean);
			}

			ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("BUSINESSE_ERROR"));
			ResponseUtil.write(response,resultDTO);
			logger.info(logInfo + "userId为空");
			return;
		}
		if (StringUtils.isBlank(extractMoney)) {
			if (StringUtils.isNotBlank(ip)) {
				IpLog.printIpLog(logBean);
			}

			ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("EXTRACTMONEY_IS_BLANK"));
			ResponseUtil.write(response,resultDTO);
			logger.info(logInfo + "extractMoney为空");
			return;
		}

		extractMoneyBD = new BigDecimal(extractMoney);
		extractFeePayBD = extractMoneyBD;

		if (!CommonUtil.isMoneyAmount(extractMoney)) {
			if (StringUtils.isNotBlank(ip)) {
				IpLog.printIpLog(logBean);
			}

			ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("EXTRACTMONEY_IS_INVALID"));
			ResponseUtil.write(response,resultDTO);
			logger.info(logInfo + "金额非法：" + extractMoneyBD.toPlainString());
			return;
		}

		if (extractMoneyBD.compareTo(BigDecimal.ZERO) <= 0) {
			if (StringUtils.isNotBlank(ip)) {
				IpLog.printIpLog(logBean);
			}

			ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("EXTRACTMONEY_IS_ZERO"));
			ResponseUtil.write(response,resultDTO);
			logger.info(logInfo + "提现金额小于或等于0：" + extractMoneyBD.toPlainString());
			return;
		}
		if (StringUtils.isBlank(recePayCardId)) {
			if (StringUtils.isNotBlank(ip)) {
				IpLog.printIpLog(logBean);
			}

			ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("BUSINESSE_ERROR"));
			ResponseUtil.write(response,resultDTO);
			logger.info(logInfo + "recePayCardId为空");
			return;
		}
		if (StrUtil.setupFlagCheck(setupFlag) == false) {
			if (StringUtils.isNotBlank(ip)) {
				IpLog.printIpLog(logBean);
			}

			ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("BUSINESSE_ERROR"));
			ResponseUtil.write(response,resultDTO);
			logger.info(logInfo + "setupFlag无效：" + setupFlag);
			return;
		}
		try {
			User user = userService.getUserDetail(userId);
			if ("2".equals(setupFlag)) {
				if (!MD5.md5(passwordCash).equals(user.getPassword_cash())) {

					ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("WRONG_PAYPASSWORD"));
					ResponseUtil.write(response,resultDTO);
					logger.info(logInfo + "提现密码错误");
					return;
				}
			}
			// 是否实名认证
			if (!"Y".equals(user.getIdcard_validate()) || !"1".equals(user.getIs_create_acct())) {
				if (StringUtils.isNotBlank(ip)) {
					IpLog.printIpLog(logBean);
				}

				ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("AUTHENTICATION_IS_NOT"));
				ResponseUtil.write(response,resultDTO);
				logger.info(logInfo + "用户没同过实名认证");
				return;
			}

			// 查询余额
			String transCode = "E300012";
			Map<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("userId", userId);
			String jsonStr = CommonUtil.constructJsonStr(transCode, userId, paramMap);
			String rtnStr = CommonUtil.getCoreValue(jsonStr);
			JSONObject balanceRtnMap = JSONObject.fromObject(rtnStr);
			if (balanceRtnMap != null && "00000".equals(balanceRtnMap.get("rescode"))) {
				String acctBalance = balanceRtnMap.get("ACCTBALANCE") + "";
				acctBalanceBD = new BigDecimal(acctBalance);
				logger.info(logInfo + "用户余额：" + acctBalance);
				if (acctBalanceBD.compareTo(extractMoneyBD) < 0) {
					if (StringUtils.isNotBlank(ip)) {
						IpLog.printIpLog(logBean);
					}

					ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("SUFFICIENT_FUNDS_IS_INCORRECT"));
					ResponseUtil.write(response,resultDTO);
					logger.info(logInfo + "用户余额不足：" + acctBalance + "，提现金额：" + extractMoneyBD.toPlainString());
					return;
				}
			} else {
				if (StringUtils.isNotBlank(ip)) {
					IpLog.printIpLog(logBean);
				}

				ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("BUSINESSE_ERROR"));
				ResponseUtil.write(response,resultDTO);
				logger.error(logInfo + "获取用户余额异常" + balanceRtnMap.get("resmsg"));
				return;
			}

			boolean userCheck = this.withdrawsCashService.userAccountCheck(userId);
			if (!userCheck) {

				ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("USER_ACCOUNT_CHECK_ERROR"));
				ResponseUtil.write(response,resultDTO);
				logger.info(logInfo + "用户账户异常");
				return;
			}
			logger.info(logInfo + "用户账户正常");

			UserRecePayCard userRecePayCard = withdrawsCashService.getRecePayBankInfo("Y", recePayCardId, userId);

			if (userRecePayCard == null) {
				if (StringUtils.isNotBlank(ip)) {
					IpLog.printIpLog(logBean);
				}

				ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("BUSINESSE_ERROR"));
				ResponseUtil.write(response,resultDTO);
				logger.info(logInfo + "用户银行卡没有绑定");
				return;
			}

			logger.info(logInfo + "用户绑定银行卡：" + userRecePayCard.getBank_name() + "，" + userRecePayCard.getCard_number());

			if (StringUtils.isNotBlank(province) && StringUtils.isNotBlank(city)) {
				userRecePayCard.setProvince(province);
				userRecePayCard.setCity(city);
				City cityObj = this.optionsService.getCityByCode(city);
				userRecePayCard.setSubbranch(cityObj.getCityName() + "支行");
				this.userCardService.updateUserCardCityAndProvince(userRecePayCard);
				logger.info(logInfo + "更新银行卡省份城市信息：" + province + "，" + cityObj.getCityName());
			}
			// 调用核心接口E340001，处理提现
			UserInfo userInfo = userService.getUserInfo(userId);
			String thirdProductCode = "";
			String thirdBankCode = "";
			String thirdPlatformCode = "";
			String extractPlatform = "";

			String extractType = "1";
			String quickWithdrawFlag = rateRisesCouponsService.findParamValueByName("quick_withdraw_flag");
			logger.info(logInfo + "快速提现开关：" + quickWithdrawFlag);

			if ("ZSHTPAY".equals(withdrawFlag)) {
				if (!"ON".equals(quickWithdrawFlag)) {

					ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("EM000000001"));
					ResponseUtil.write(response,resultDTO);
					logger.info(logInfo + "快速提现已关闭");
					return;
				}
				extractType = "2";
				String bankName = userRecePayCard.getBank_name();
				String productCode = "quick_withdraw";
				String phoneNumber = userInfo.getPhone_no();
				String reqOrderId = "-1";
				logger.info(logInfo + "根据银行名称获取快速提现路由：" + bankName);
				List<ThirdProductRoute> thirdProductRoutes = thirdProductRouteService.getThirdProductRoutes(bankName,
						productCode);
				if (thirdProductRoutes == null || thirdProductRoutes.size() == 0) {
					logger.error(logInfo + "根据银行名称获取快速提现路由失败" + bankName + "-" + productCode);
					try {
						sMSService.sendErrorMessageForSystem("sms05004", "", phoneNumber, reqOrderId,
								logInfo + "-根据银行名称获取快速提现路由失败-" + bankName + "-" + productCode);
					} catch (Exception e) {
						logger.error(logInfo + "发送运营短信异常", e);
					}

					ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("EM000000001"));
					ResponseUtil.write(response,resultDTO);
					return;
				}
				ThirdProductRoute routeProduct = thirdProductRoutes.get(0);
				thirdPlatformCode = routeProduct.getThirdPlatformCode();
				thirdProductCode = routeProduct.getThirdProductCode();
				logger.info(logInfo + "银行名称" + bankName);
				logger.info(logInfo + "第三方产品代码" + thirdProductCode);
				logger.info(logInfo + "第三方平台" + thirdPlatformCode);

				extractPlatform = "-1";
				if ("quick_withdraw_payplam".equals(thirdProductCode)) {
					extractPlatform = "2";
				} else if ("quick_withdraw_tonglian".equals(thirdProductCode)) {
					extractPlatform = "3";
				} else if ("quick_withdraw_zhongxinbank".equals(thirdProductCode)) {
					extractPlatform = "4";
				} else if ("quick_withdraw_changjie".equals(thirdProductCode)) {
					extractPlatform = "5";
				} else if("quick_withdraw_fuyoudsf".equals(thirdProductCode)){
					extractPlatform = "6";
				}else{
					logger.error(logInfo + "没有找到提现平台对应码" + thirdProductCode);
				}
				logger.info(logInfo + "根据银行名称获取第三方平台银行：" + bankName);
				ThirdPlatformBank thirdPlatformBank = thirdProductRouteService.getThirdPlatFormBank(bankName,
						thirdPlatformCode);
				if (thirdPlatformBank == null) {
					logger.error(logInfo + "根据银行名称获取第三方平台银行失败" + bankName + "-" + thirdProductCode);
					sMSService.sendErrorMessageForSystem("sms05004", "", phoneNumber, reqOrderId,
							logInfo + "根据银行名称获取第三方平台银行失败" + bankName + "-" + thirdProductCode);

					ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("EM000000001"));
					ResponseUtil.write(response,resultDTO);
					return;
				}
				thirdBankCode = thirdPlatformBank.getThirdPlatformBankCode();
				logger.info(logInfo + "第三方平台银行代码" + thirdBankCode);
			}
			transCode = "E330014";
			paramMap.put("extractMoney", extractMoney);// 提现金额
			paramMap.put("acctType", 7);// acctType提现账户类型(1.机构主账户,2.机构收益户,3.机构回款户,4.机构风险金户,5.个人债权户,6.个人债务户,7.个人主账户)
			paramMap.put("extractCardNo", userRecePayCard.getCard_number());// 提现卡号
			paramMap.put("openBank", userRecePayCard.getBank_name());// 开户行
			paramMap.put("openBankName", userRecePayCard.getAccount_name());// 开户名
			paramMap.put("userName", userInfo.getReal_name());// 用户名称(个人或者机构),提现人或提现机构的名称
			paramMap.put("identityNo", userInfo.getId_card());// 身份证号
			paramMap.put("email", user.getEmail() == null ? "" : user.getEmail());// 邮箱
			paramMap.put("phoneNo", userInfo.getPhone_no() == null ? "" : userInfo.getPhone_no());// 电话号码
			paramMap.put("withdrawFlag", withdrawFlag);// 前台提现标识
			paramMap.put("extractPlatform", extractPlatform); // 快速提现路由平台
			paramMap.put("extractType", extractType);
			Map<String, Object> resultMap = this.withdrawsCashService.dealWithdrawl(extractType, transCode, paramMap,
					userRecePayCard, thirdProductCode, thirdBankCode, thirdPlatformCode);

			ResultDTO result = new ResultDTO(ResultCode.SUCCESS);
			result.setRecord(resultMap);
			ResponseUtil.write(response,result);
			return;
		} catch (Exception e) {
			logger.info(logInfo + "提现异常", e);
			if (StringUtils.isNotBlank(ip)) {
				IpLog.printIpLog(logBean);
			}
			ResultDTO resultDTO=errorMessageService.getResultDtoByErrorMessge(errorMessageService.getErrorMessage("WITHDRAW_ERROR"));
			ResponseUtil.write(response,resultDTO);
			return;
		}
	}
	
	
	/**
	 *  查询路由银行信息列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryRouteBankList")
	public void queryRouteBankList(HttpServletRequest request, HttpServletResponse response){
		
		try{
			if (!RequestUtil.validSign(request)) {
				logger.info("无效签名");
				ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
				return;
			}
			if (!RequestUtil.validToken(request)) {
				logger.info("无效token");
				ResponseUtil.write(response, ResultConstant.INVALID_TOKEN);
				return;
			}
			RequestHeader header = RequestUtil.decodeHeader(request);
			logger.info("header：" + header.toString());
			
			Long userIdLong = header.getUserId();
			if (userIdLong == null) {
				ResponseUtil.write(response, ResultConstant.NOT_LOGIN);
				return;
			}
		    User user = this.userService.getUserDetail(userIdLong.toString());
		    if(user==null){
		    	ResultDTO<String> result = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, result);
				return;
		    }
		    
			// 解密请求参数
			com.alibaba.fastjson.JSONObject jsonMap = RequestUtil.decodeDataJson(request);
			logger.info("data：" + jsonMap.toString());
			
			Map<String, Object> paramsMap = new HashMap<String,Object>();
			
			String bankFlg = jsonMap.getString("bankFlg");
			
			if(StringUtils.isBlank(bankFlg)){
				bankFlg = "KJ";
			}

			paramsMap.put("bankFlg", bankFlg);
			ResultDTO<Map<String,String>> resultDTO = this.thirdProductRouteService.queryRouteBankList(paramsMap);
		    ResponseUtil.write(response, resultDTO);
			return;
			
		}catch (Exception e) {
			ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			ResponseUtil.write(response, checkDto);
			return;
		}
	}
	
	/**
	 * 查询用户相关充值信息
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryRechargeInfo")
	public void queryRechargeInfo(HttpServletRequest request, HttpServletResponse response){
		String logInfo = "查询用户相关充值信息—getRecePayBank ";
		try{
			if (!RequestUtil.validSign(request)) {
				logger.info("无效签名");
				ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
				return;
			}
			if (!RequestUtil.validToken(request)) {
				logger.info("无效token");
				ResponseUtil.write(response, ResultConstant.INVALID_TOKEN);
				return;
			}
			RequestHeader header = RequestUtil.decodeHeader(request);
			logger.info("header：" + header.toString());
			
			Long userIdLong = header.getUserId();
			if (userIdLong == null) {
				ResponseUtil.write(response, ResultConstant.NOT_LOGIN);
				return;
			}
		    User user = this.userService.getUserDetail(userIdLong.toString());
		    if(user==null){
		    	ResultDTO<String> result = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, result);
				return;
		    }
		    
			
			// 用户id
			String userId = userIdLong.toString();
			logInfo=logInfo+userId;
			Map<String,Object> resultMap = new HashMap<String,Object>();
			//判断是否实名认证
			String idcardValidate = user.getIdcard_validate();
			
			if(idcardValidate.equals("Y")){
				HashMap<String,Object> userPayCdParam = new HashMap<String,Object>();
				userPayCdParam.put("isValid","Y");
				userPayCdParam.put("userId", userId);
				userPayCdParam.put("isBinding", "Y");
				UserBankCardVo userRecePayCard =centerService.getRecePayBank(userPayCdParam);

				if (userRecePayCard == null) {
					resultMap =BeanUtil.getMapFromBean(new UserBankCardVo());
				} else {
					resultMap =(BeanUtil.getMapFromBean(userRecePayCard));
				}
			}else{
				resultMap = BeanUtil.getMapFromBean(new UserBankCardVo());
			}
			
			

			//查询当月剩余快速提现次数
			Map<String,Object> userQuickReqMap = new HashMap<String,Object>();
			userQuickReqMap.put("userId", userId);
			//判断当月是否还有快速提现次数
			String quickAmountDesc = "";
			
			UserQuickWithdraw userQuickWithdraw = this.userCardService.queryUserQuickCountByUserId(userQuickReqMap);
			Integer quickWithdrawCount = 0;
			
			String extractTip = userService.getSysSettingHtmlInfo("t_extract_tip");
			if(userQuickWithdraw!=null){
				quickWithdrawCount = userQuickWithdraw.getDays_quick_count();
				
				if(quickWithdrawCount<0){
					quickWithdrawCount = 0;
				}
			}
			
			//添加快速提现相关提示信息
			String systemQuickAmount = userQuickWithdraw==null?rateRisesCouponsService.findParamValueByName("quick_withdraw_amount"):userQuickWithdraw.getQuick_withdraw_amount().toString();
			logger.info(logInfo+" 添加快速提现相关提示信息:"+systemQuickAmount);
			Map<String,String> phMap = new HashMap<String,String>();
			phMap.put("quickExtractAmount", systemQuickAmount);
			phMap.put("quickExtractCount", quickWithdrawCount.toString());
			
			quickAmountDesc = PlaceholderUtils.resolvePlaceholders(extractTip, phMap);
			logger.info(logInfo+" 判断当月是否还有快速提现次数:"+quickAmountDesc);
			//查询提现开关
			String quickWithdrawFlag = rateRisesCouponsService.findParamValueByName("quick_withdraw_flag");
			logger.info(logInfo+" 查询提现开关:"+quickWithdrawFlag);
			resultMap.put("quickAmountDesc",quickAmountDesc);
			resultMap.put("quickCountDesc","");
			resultMap.put("quickWithdrawCount",quickWithdrawCount);
			resultMap.put("systemQuickAmount",systemQuickAmount);
			resultMap.put("quickWithdrawFlag", quickWithdrawFlag);
			resultMap.put("extractNumberTip", "");

			//查询主账户余额
			
			Map resMap = centerService.getCusBalance(userQuickReqMap);
			String acctBalance = "0.0";
			if (resMap != null && "00000".equals(resMap.get("rescode"))) {
				acctBalance = resMap.get("ACCTBALANCE") + "";
				resultMap.put("balanceMoney", acctBalance == null || "".equals(acctBalance) ? "0.00" : acctBalance);// 余额
			} else {
				logger.error("查询主账户余额失败:" + resMap.get("resmsg"));
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.QUERY_FAILED);
				ResponseUtil.write(response, checkDto);
				return;
			}
			//查询回款卡号id
			UserRecePayCard userRecePayCard = withdrawsCashService.getRecePayBankInfoByUserId(userId);
			String recePayCardId = String.valueOf(userRecePayCard.getId());
			resultMap.put("recePayCardId",recePayCardId);

			logger.info(logInfo+"结束");
			ResultDTO<Map<String,Object>> resultDTO=new ResultDTO<Map<String,Object>>(ResultCode.SUCCESS,Consts.SUCCESS_DESCRIBE);
			resultDTO.setRecord(resultMap);
			ResponseUtil.write(response,resultDTO);
			
		}catch (Exception e) {
			ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			ResponseUtil.write(response, checkDto);
			return;
		}
	}
	
	/**
	 * 更改银行手机号
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/saveCardPhoneNumber")
	public void saveCardPhoneNumber(HttpServletRequest request, HttpServletResponse response){
		String logInfo = "更新手机号—saveCardPhoneNumber ";
		try{
			if (!RequestUtil.validSign(request)) {
				logger.info("无效签名");
				ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
				return;
			}
			if (!RequestUtil.validToken(request)) {
				logger.info("无效token");
				ResponseUtil.write(response, ResultConstant.INVALID_TOKEN);
				return;
			}
			RequestHeader header = RequestUtil.decodeHeader(request);
			logger.info("header：" + header.toString());
			
			Long userIdLong = header.getUserId();
			if (userIdLong == null) {
				ResponseUtil.write(response, ResultConstant.NOT_LOGIN);
				return;
			}
		    User user = this.userService.getUserDetail(userIdLong.toString());
		    if(user==null){
		    	ResultDTO<String> result = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, result);
				return;
		    }
			
		    // 解密请求参数
 			logInfo="用户ID="+userIdLong;
 			com.alibaba.fastjson.JSONObject jsonMap = RequestUtil.decodeDataJson(request);
 			logger.info("data：" + jsonMap.toString());
 			
 			String userId = userIdLong.toString();   // 用户id
 			String cardNumber = jsonMap.getString("cardNumber");
 			String mobile = jsonMap.getString("mobile");
			
 			Map<String, String> paramsMap = new HashMap<String,String>();
			
			paramsMap.put("userId", userId);
			paramsMap.put("cardNumber", cardNumber);
			paramsMap.put("mobile", mobile);
			
			
			// 用户id为空
			if (StringUtils.isBlank(userId)) {
				logger.info(logInfo+"更新手机号：用户Id为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			if (StringUtils.isBlank(cardNumber)) {
				logger.info(logInfo+"更新手机号：cardNumber为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			if (StringUtils.isBlank(mobile)) {
				logger.info(logInfo+"更新手机号：mobile为空");
				
				ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
						Message.CnDescriptionExpression.BUSINESSE_ERROR);
				ResponseUtil.write(response, checkDto);
				return;
			}
			
			ResultDTO resultDTO = this.thirdProductRouteService.saveCardPhoneNumber(paramsMap);
		    ResponseUtil.write(response, resultDTO);
			return;
			
		}catch (Exception e) {
			ResultDTO<String> checkDto = new ResultDTO<>(ResultCode.FAILED,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			ResponseUtil.write(response, checkDto);
			return;
		}
			
	}
	
}
